package com.uzai.console.service.feign.impl;

import com.uzai.common.result.ResponseCode;
import com.uzai.console.common.UzaiRespVo;
import com.uzai.console.dto.feign.pddorder.*;
import com.uzai.console.service.feign.PddOrderFeignService;
import com.uzai.console.vo.pdd.pddorder.feign.PddOrderBindVo;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: jianghan
 * @Date: 2021/11/24 16:24
 * @Description:
 */
@Component
public class PddOrderFeignFallbackFactory implements FallbackFactory<PddOrderFeignService> {

    private static Logger logger = LoggerFactory.getLogger(PddOrderFeignFallbackFactory.class);

    @Override
    public PddOrderFeignService create(Throwable throwable) {

        logger.error("--拼多多订单调用微服务出错，err:={}", throwable);

        return new PddOrderFeignService() {
            @Override
            public UzaiRespVo<Object> settled(PddOrderSettledDto pddOrderSettledDto) {
                UzaiRespVo<Object> uzaiRespVo= new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Object> unfreeze(PddOrderUnfreezeDto pddOrderUnfreezeDto) {
                UzaiRespVo<Object> uzaiRespVo= new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Object> unbind(PddOrderUnbindDto pddOrderUnbindDto) {
                UzaiRespVo<Object> uzaiRespVo= new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Object> bind(PddOrderBindDto pddOrderBindDto) {
                UzaiRespVo<Object>  uzaiRespVo = new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }

            @Override
            public UzaiRespVo<Boolean> pull(PddOrderPullDto pddOrderPullDto) {
                UzaiRespVo<Boolean>  uzaiRespVo = new UzaiRespVo<>();
                uzaiRespVo.setData(false);
                uzaiRespVo.setCode(ResponseCode.ERROR);
                uzaiRespVo.setTime(System.currentTimeMillis());
                uzaiRespVo.setMsg("调用失败");
                return uzaiRespVo;
            }
        };
    }

}
